package com.jy.adscm.operation.xjfile.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.jy.adscm.bean.system.JyUser;
import com.jy.adscm.operation.xjfile.bean.XjAttachment;
import com.jy.adscm.operation.xjfile.mapper.mysql.XjAttachmentMapper;
import com.jy.adscm.operation.xjfile.service.XjAttachmentService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.jy.adscm.system.mapper.mysql.JyUserMapper;
import com.jy.adscm.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zyl
 * @since 2019-05-07
 */
@Service
public class XjAttachmentServiceImpl extends ServiceImpl<XjAttachmentMapper, XjAttachment> implements XjAttachmentService {
    @Autowired
    JyUserMapper jyUserMapper;
    @Override
    public List<XjAttachment> selectByXid(Integer xid, Integer type) {
        Wrapper<XjAttachment> wrapper =new EntityWrapper<>();
        wrapper.eq("xid",xid);
        wrapper.eq("type",type);
        List<XjAttachment> xjAttachments = super.selectList(wrapper);
        for (XjAttachment xjAttachment : xjAttachments) {
            if(AdscmBaseUtils.getInstance().isNotEmpty(xjAttachment.getUploader(),null)){
                JyUser jyUser = jyUserMapper.selectById(xjAttachment.getUploader());
                xjAttachment.setUploaderName(jyUser.getName());
            }
        }
        return xjAttachments;
    }
}
